﻿using System;
using System.IO;

namespace Excel_2010_Measure_Reader
{
    public static class ExcelFiles
    {
        public static FileMeasureSetList ReadAllMeasures(ExcelTreeView directoryTree)
        {
            var fileMeasuresList = new FileMeasureSetList();

            foreach (var path in directoryTree.GetFilePaths())
            {
                var fileMeasureSet = new FileMeasureSet
                {
                    FileName = Path.GetFileName(path),
                    DirectoryName = Path.GetDirectoryName(path)
                };

                try
                {
                    var excel = new ExcelFile(path);
                    excel.GetMeasures(fileMeasureSet.Measures);
                }

                catch (ExcelException ex)
                {
                    fileMeasureSet.ErrorMessage = ex.Message;
                }

                catch (Exception ex)
                {
                    fileMeasureSet.ErrorMessage = ex.Message;
                }

                fileMeasuresList.Add(fileMeasureSet);
            }
            return fileMeasuresList;
        }
    }
}